package io.cucumber.core.runner;

import com.zws.cucumber.ZwsUtils;

import java.util.ArrayList;
import java.util.List;

public class CoreRunnerTestStepHelper {

    public static List<PickleStepTestStep> cloneTestSteps(List<? extends io.cucumber.plugin.event.TestStep> originalList, int skipSteps) {
        List<PickleStepTestStep> list = new ArrayList();
        for (int i = skipSteps; i < originalList.size(); i++) {
            io.cucumber.plugin.event.TestStep originalStep = originalList.get(i);
            list.add(clonePickleStepTestStep(originalStep));
        }
        return list;
    }

    private static PickleStepTestStep clonePickleStepTestStep(io.cucumber.plugin.event.TestStep eventTestStep) {
        PickleStepTestStep origin = (PickleStepTestStep) eventTestStep;
        PickleStepDefinitionMatch originalMatch = origin.getDefinitionMatch();
        PickleStepDefinitionMatch match = new PickleStepDefinitionMatch(
                new ArrayList<>(originalMatch.getArguments()),
                originalMatch.getStepDefinition(),
                ZwsUtils.getFieldValue(PickleStepDefinitionMatch.class, "uri", originalMatch),
                origin.getStep());
        return new PickleStepTestStep(
                origin.getId(),
                origin.getUri(),
                origin.getStep(),
                origin.getBeforeStepHookSteps(),
                origin.getAfterStepHookSteps(),
                match);
    }

//    public static PickleStepTestStep newSnapshotTakePickleStepTestStep(Supplier<ZwsSnapshotFacade> snapshotFacadeSupplier, String snapshotName) {
//        return new PickleStepTestStep(
//                UUID.randomUUID(),
//                null,
//                new NoStep("[OPTIMIZATION STEP] take snapshot"),
//                Collections.emptyList(),
//                Collections.emptyList(),
//                new SnapshotTakeStepDefinitionMatch(snapshotFacadeSupplier, snapshotName));
//    }
//
//    public static PickleStepTestStep newSnapshotRestorePickleStepTestStep(Supplier<ZwsSnapshotFacade> snapshotFacadeSupplier, String snapshotName, String skipStepsText) {
//        return new PickleStepTestStep(
//                UUID.randomUUID(),
//                null,
//                new NoStep("[OPTIMIZATION STEP] restore snapshot"),
//                Collections.emptyList(),
//                Collections.emptyList(),
//                new SnapshotRestoreStepDefinitionMatch(snapshotFacadeSupplier, snapshotName, skipStepsText));
//    }
//
//    public static PickleStepTestStep newSnapshotDeletePickleStepTestStep(Supplier<ZwsSnapshotFacade> snapshotFacadeSupplier, String snapshotName) {
//        return new PickleStepTestStep(
//                UUID.randomUUID(),
//                null,
//                new NoStep("[OPTIMIZATION STEP] delete snapshot"),
//                Collections.emptyList(),
//                Collections.emptyList(),
//                new SnapshotDeleteStepDefinitionMatch(snapshotFacadeSupplier, snapshotName));
//    }
}
